
layui.use(['layer','form'], function(){
    var layer = layui.layer;
    var form = layui.form;

    form.verify({
        username: function(value, item){ //value：表单的值、item：表单的DOM对象
            if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                return '姓名不能有特殊字符';
            }
            if(/(^\_)|(\__)|(\_+$)/.test(value)){
                return '姓名首尾不能出现下划线\'_\'';
            }
            if(/^\d+\d+\d$/.test(value)){
                return '姓名不能为数字';
            }
        }
    });

    //监听提交
    form.on('submit(submitAsk)', function(data){
        /*layer.msg(JSON.stringify(data.field));
        return false;*/
        $.ajax({
            url:'/user/ask',
            method:'post',
            data:data.field,
            dataType:'JSON',
            success:function(res){
               layer.msg("提问成功！谢谢您！！！");
            },
            error:function (data) {
            }
        })
        return false;
    });
    // layer.msg('Hello World');
});